<?php
$theme_name = 'nm_zone';

//adding thumbnail support in the theme
add_theme_support('post-thumbnails');

//adding custom image size for post thumbnail
add_image_size( 'home-posts', 250, 250, false);

// adding read more link using except filter
function nm_new_excerpt_more($more) {
	global $post;
	return '<a href="'. get_permalink($post->ID) . '">  Read more...</a>';
}
add_filter('excerpt_more', 'nm_new_excerpt_more');




	
	// Add RSS links to <head> section
	automatic_feed_links();
	
	// Load jQuery
	if ( !is_admin() ) {
	   wp_deregister_script('jquery');
	   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"), false);
	   wp_enqueue_script('jquery');
	}
	
	// Clean up the <head>
	function removeHeadLinks() {
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    }
    add_action('init', 'removeHeadLinks');
    remove_action('wp_head', 'wp_generator');
    
	// Declare sidebar widget zone
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Sidebar Widgets',
    		'id'   => 'sidebar-widgets',
    		'description'   => 'These are widgets for the sidebar.',
    		'before_widget' => '',
    		'after_widget'  => '',
    		'before_title'  => '<h1>',
    		'after_title'   => '</h1>'
    	));
    }
    
	// Declare Widget Zone At Home
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Home Widget One',
    		'id'   => 'home_widget_one',
    		'description'   => 'First Home Page Widget',
    		'before_widget' => '',
    		'after_widget'  => '',
    		'before_title'  => '<h1>',
    		'after_title'   => '</h1>'
    	));
		
		
    	register_sidebar(array(
    		'name' => 'Home Widget Two',
    		'id'   => 'home_widget_two',
    		'description'   => 'Second Home Page Widget',
    		'before_widget' => '',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h1>',
    		'after_title'   => '</h1>'
    	));
    	register_sidebar(array(
    		'name' => 'Home Widget Three',
    		'id'   => 'home_widget_three',
    		'description'   => 'First Home Page Widget',
    		'before_widget' => '',
    		'after_widget'  => '',
    		'before_title'  => '<h1>',
    		'after_title'   => '</h1>'
    	));
		
		
    	register_sidebar(array(
    		'name' => 'Home Widget Four',
    		'id'   => 'home_widget_four',
    		'description'   => 'Second Home Page Widget',
    		'before_widget' => '',
    		'after_widget'  => '',
    		'before_title'  => '<h1>',
    		'after_title'   => '</h1>'
    	));
    }
	
    if (function_exists('primary_menu')) {	
		register_nav_menu (
			array ( 'main-nav' => 'Main Navigation Menu' )
		);
	}
	
	if (function_exists('secondary_menu')) {	
		register_nav_menu (
			array ( 'footer-menu' => 'Footer Menu' )
		);
	}
	

///////////// adding menue in admin-panel	
add_action('admin_menu',"nm_addMainMenue");

function nm_addMainMenue(){
	add_menu_page('Armchair Wedding Guru', 'Armchair Wedding Guru', 'administrator', 'nm_main_menue', 'nm_Main_Menue', NULL, 6); 
	add_submenu_page("nm_main_menue", "Days Out", "Days Out", "administrator", "nm_days_out", "nm_Days_Out" );
}

function nm_Main_Menue(){
   echo "Admin Page Test";	
}

function nm_Days_Out(){
	include TEMPLATEPATH . "/daysOutEntry.php";
}

////////////////////////// adding totoal post visits
function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

///////////// adding custom column in posts listings in admin panel to show total visits of posts
add_filter('manage_posts_columns', 'my_column');
function my_column($defaults){
	$defaults['my_column'] = __('Total Visits');	/*Add our column to the list of default columns*/
	return $defaults;
}
add_action('manage_posts_custom_column', 'custom_column_data', 10, 2);
function custom_column_data($column_name, $id) {
    if( $column_name == 'my_column' ) {
		 echo getPostViews($id);
	}
}



?>